package com.seqb.common.config;

import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author lilinshen
 * @title 请填写标题
 * @description 请填写相关描述
 * @date 2019/11/15
 */
@Component
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    SeqbConfig seqbConfig;

    /**
     * 定义files文件路径处理
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/files/**").addResourceLocations("file:///" + seqbConfig.getUploadPath());
    }

    /**
     * 定义thymeleaf的全局变量
     */
    @Resource
    private void configureThymeleafStaticVariables(ThymeleafViewResolver viewResolver) {
        if (viewResolver != null) {
            Map<String, Object> staticVariables = Maps.newHashMap();
            staticVariables.put("srvn", "20191126");                 //静态资源版本号
            viewResolver.setStaticVariables(staticVariables);
        }
    }

}